import re
from typing import Optional
from config import config
from model.model import Result, Info


class ServiceInterface:

    @classmethod
    def get_prefix_pattern(cls) -> str:
        pass

    @classmethod
    def make_url(cls, index) -> str:
        pass

    @classmethod
    def get_url(cls, text: str) -> Optional[str]:
        urls = re.findall(r'(?<=' + cls.get_prefix_pattern() + ')\w+', text, re.I | re.M)
        if urls:
            return cls.make_url(urls[0])
        return None

    @classmethod
    def index(cls, url) -> Optional[str]:
        index = re.findall(r'(?<=com\/)\w+', url)
        try:
            return index[0]
        except IndexError:
            return None

    @classmethod
    def get_info(cls, url: str) -> Result:
        """
        获取作品信息
        :param url:
        :return:
        """
        pass

    @classmethod
    def download_header(cls) -> dict:
        return {
            "accept": "*/*",
            "accept-encoding": "gzip, deflate, br",
            "Upgrade-Insecure-Requests": '1',
            "user-agent": config.user_agent
        }

    @classmethod
    def complex_download(cls, info: Info):
        pass

